#pragma once

#include <string>
#include <filesystem>
#include "memdb/memdb.h"

namespace memdb {
namespace impl {
class IMeta;
class Factory;
}//namespace impl
}//namespace memdb

namespace memdb {
namespace impl {
namespace simple {

class SimpleDB : public memdb::IDB {
public:
  SimpleDB(const std::string & name, const std::string & dir = ".");
  ~SimpleDB() override;

public:
  std::error_code open() override ;

  std::error_code close() override ;

	bool isOpened() const override { return _opened; }

  std::error_code destroy() override ;

  bool exists() const override ;

  ITables & tables() const override ;

  const std::filesystem::path & dbPath() const ;

private:
  std::error_code _open();
  std::error_code _create();

private:
  std::string _name;
  std::filesystem::path _dir; //parent 
	std::unique_ptr<const memdb::impl::Factory> _factory;

	std::unique_ptr<memdb::impl::IMeta> _meta;
	std::unique_ptr<ITables> _tables;
	bool _opened = false;
};

}//namespace simple
}//namespace impl
}//namespace memdb
